<%@page import="com.yyj.domain.Goods"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="css/goods.css" type="text/css" >
</head>
<body>

<div class="header">
<c:set var="user" scope="session" value="${user}"/>
<c:choose>
   <c:when test="${empty user }">
<div id="header">
<a href="${pageContext.request.contextPath}/home.do">返回首页</a>
<a href="${pageContext.request.contextPath}/login.do">登录</a>
<a href="${pageContext.request.contextPath}/home.do">免费注册</a>
</div>
</c:when>
<c:otherwise>
<div id="header">
<a href="${pageContext.request.contextPath}/home.do">返回首页</a>
<form action="${pageContext.request.contextPath }/my.do" id="u-form">
<input type="text" value="${user.account }" id="account">
<input type="submit" value="你好${user.nickname }" id="t-user">
</form>
</div>
</c:otherwise>
</c:choose>
</div>

<div class="sousuo">
 <div class="f-sousuo">
<form action="${pageContext.request.contextPath}/selectgoods.do" id="f-sousuo">
<input type="text" name="name" id="goods" placeholder="搜索 你想找的商品">
<input type="submit" value="搜索" id="sousuo">
</form>
</div>
</div> 

<div id="g-top">
  <div>
 <img src="img/${goods.avator }" id="g-img">
  </div>
  <div id="goods-der">
 <label id="g-d">${goods.description }</label>
    <div id="g-shop">
       <label id="name">${goods.name }</label>
       <label id="shop">${goods.shop }</label>
    </div>
  <label id="money">￥${goods.sum }</label>
       <div id="g-address">
       <label>收货地址：</label>
  <label id="dizhi">${user.address }</label>
       </div>
      <div id="g-n">
  <label id="number">库存${goods.number }件</label>
        <div id="s-number">
         <label>选择数量:</label>
            <div id="select">
               <img alt="" src="img/jian.png" id="jian" onclick="changeslie(-1)">
               <input type="text" id="us-num" value="1" onclick="insert()">
               <img alt="" src="img/jia.png" id="jia" onclick="changeslie(1)">
            </div>
        </div>
       </div>
       
       <div id="buy">
       <form action="${pageContext.request.contextPath }/balance.do">
       <input type="text" name="goods_id" value="${goods.goods_id }" id="bala">
        <input type="text" name="avator" value="${goods.avator }" id="bala">
        <input type="text" name="goods" value="${goods.description }" id="bala">
         <input type="text" name="goods_name" value="${goods.name }" id="bala">
         <input type="text" name="sum" value="${goods.sum }" id="bala">
            <input type="text" name="number" id="nu" >
            <input type="text" name="address" value="${user.address }" id="bala">
             <input type="text" name="phone" value="${user.phone }" id="bala">
              <input type="text" name="account" value="${user.nickname }" id="bala">
       <input type="submit" value="立即购买" id="u-buy">
       </form>
          <div class="gwc">
          <label id="wen">加入购物车</label>
          <img src="img/gwct.png" id="gwct">
          
          <form action="${pageContext.request.contextPath }/insertgwc.do">
          <input type="text" name="user_id" value="${user.account }" id="gw-none">
          <input type="text" name="goods_id" value="${goods.goods_id }" id="gw-none">
          <input type="text" name="merchant" value="${goods.shop }" id="gw-none">
          <input type="text" name="image" value="${goods.avator }" id="gw-none">
          <input type="text" name="description" value="${goods.description }" id="gw-none">
          <input type="text" name="price" value="${goods.sum }" id="gw-none">
          <input type="text" name="number"  id="num">
          <input type="text" name="sum" value="${goods.sum }" id="sums" style="display:none;">
          <input type="submit" value="购物车" id="gwcar">
          </form>
          </div>
       </div>
       
       <div id="z-sum">
                   总计￥<label id="show-sum">${goods.sum }</label>元
       </div>
  </div>
</div>





<script type="text/javascript" src="${pageContext.request.contextPath }/js/jquery-1.11.3.min.js">
</script>
<script type="text/javascript">

document.getElementById("nu").value=1;
document.getElementById("num").value=1;
 function changeslie(n){
	 var index=parseInt(document.getElementById("us-num").value);
	 var i=parseInt(n);
	 var t=index+i;
	 showslie(t);
 }
 function showslie(t){
	 if(t<1){
		 document.getElementById("us-num").value=1;
		 document.getElementById("nu").value=1;
		 document.getElementById("num").value=1;
			 document.getElementById("show-sum").innerHTML=s*${goods.sum};
	 }
	 else if (t>${goods.number}){
		 document.getElementById("us-num").value=${goods.number};
		 document.getElementById("nu").value=${goods.number};
		 document.getElementById("num").value=${goods.number};

	 }
	 else{
		 document.getElementById("us-num").value=t;
		 document.getElementById("nu").value=t;
		 document.getElementById("num").value=t;
		 document.getElementById("show-sum").innerHTML=t*${goods.sum};
	 }
 }
 function insert(){
	 var z= document.getElementById("us-num").value;
	 document.getElementById("nu").value=z;
	 document.getElementById("num").value=z;
	 if(z>${goods.number}){
		 alert("数量过多");
		 document.getElementById("us-num").value=1;
		 document.getElementById("nu").value=1;
		 document.getElementById("num").value=1;
		 document.getElementById("show-sum").innerHTML=${goods.sum};
	 }
	 else if(z<1){
		 alert("至少选择一件");
		 document.getElementById("us-num").value=1;
		 document.getElementById("nu").value=1;
		 document.getElementById("num").value=1;
		 document.getElementById("show-sum").innerHTML=${goods.sum};
	 }else{
	 document.getElementById("show-sum").innerHTML=z*${goods.sum};
 }
 }
</script>
</body>
</html>